import com.alibaba.druid.pool.DruidDataSource;


import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/jdbc");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setInitialSize(1);  //连接池初始化大小
        dataSource.setMaxActive(10); //最大连接数
        dataSource.setMinIdle(1); //最小连接数
        dataSource.setMaxWait(6000); //最大等待时间
        dataSource.setValidationQuery("select 1"); //验证连接
        dataSource.setTestOnBorrow(true); //验证连接
         dataSource.setTestOnReturn(true);  //验证连接
        dataSource.setTestWhileIdle(true); //验证连接
        dataSource.setTimeBetweenEvictionRunsMillis(60000);
        try {
            if(dataSource.getConnection()!=null){
                System.out.println("连接成功");
            }else{
                System.out.println("连接失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    }
